<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>创建一个动画类</title>
</head>
<body>
    <script>
        var Anim = function() {};

        // 写法1
        /* Anim.prototype.start = function() {
            console.log("anim start")
        };
        Anim.prototype.stop = function() {
            console.log("anim stop")
        }; */

        // 写法2
        /* Anim.prototype = {
            start: function () {
                console.log("anim start")
            },
            stop: function () {
                console.log("anim stop")
            }
        }; */

        // 写法3
        /* Function.prototype.method = function(name, fn) {
            this.prototype[name] = fn;
        };

        Anim.method('start', function () {
            console.log("anim start")
        });

        Anim.method('stop', function () {
            console.log("anim stop")
        }); */

        // 写法4
        Function.prototype.method = function(name, fn) {
            this.prototype[name] = fn;
            return this;
        };

        Anim.method('start', function () {
            console.log("anim start")
        }).method('stop', function () {
            console.log("anim stop")
        });
        
        var anim = new Anim();
        anim.start();
        anim.stop();
    </script>
</body>
</html>